import React, { Component, Suspense } from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'

export class Routerview extends Component {
  render() {
      const {routerConfig }=this.props
    return (
        <Suspense fallback="路由加载中">
            <Switch>
                {
                    routerConfig ?routerConfig.map((item,index)=>{
                      return item.redirect ?<Redirect to={item.redirect} key={index}></Redirect>
                       :<Route path={item.path}
                        render={(props)=>{
                          if(props.location.pathname!=="/login"){
                            let user =location.getItem("user") ?
                            JSON.parse(localStorage.getItem("user"))
                            :{}
                            if(!user.phone){
                              props.history.push("/login")
                            }
                          }
                       return     <item.component {...props} routerConfig={item.children}></item.component>     
                       }} ></Route>
                     }) :'暂无数据'
                }


            </Switch>
        </Suspense> 
    )
  }
}

export default Routerview